import Vue from 'vue'
import bus from '../vuex/bus.js'
import Router from 'vue-router'

Vue.use(Router);

var router = new Router({
	routes: [{
			path: '/',
			name: 'login',
			component: resolve => require(['../components/login.vue'], resolve)
		},
		{
			path: '/search/:kdno',
			name: 'search',
			component: resolve => require(['../components/search.vue'], resolve)
		},
		{
			path: '/myexpress',
			name: 'myexpress',
			component: resolve => require(['../components/myexpress.vue'], resolve),
		},
		{
			path: '/addexpress',
			name: 'addexpress',
			component: resolve => require(['../components/addExpress.vue'], resolve),
		},
		{
			path: '/helpother',
			name: 'helpother',
			component: resolve => require(['../components/helpother.vue'], resolve)
		},
		{
			path: '/personalcenter',
			name: 'personalcenter',
			component: resolve => require(['../components/personalcenter.vue'], resolve)
		},
		{
			path: '/comingsoon',
			name: 'comingsoon',
			component: resolve => require(['../components/comingSoon.vue'], resolve),
	}],
});
router.beforeEach((to, from, next) => {
	next();
});
router.afterEach(route => {
	autoChangeSelectMenu(route);
});
// 当路由变化的时候自动匹配当前选中的菜单
var autoChangeSelectMenu = (to) => {
	var selectedMenu;
	switch (to.name) {
		case 'helpother':
			selectedMenu = 2;
			break;
		case 'myexpress':
			selectedMenu = 3;
			break;
		case 'addexpress':
			selectedMenu = 3;
			break;
		case 'personalcenter':
			selectedMenu = 4;
			break;
		default:
			selectedMenu = 1;
			break;
	};
	bus.$emit('selecteMenuChanged', selectedMenu);
}
export default router;
